package com.contract.spirit.ui.withdraw

import android.text.TextUtils
import android.widget.Button
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.contract.spirit.func.utils.CheckTools.isCorrectNumber
import java.math.BigDecimal

/**
 * @author: witness
 * created: 2021/9/29
 **/

@BindingAdapter(value = ["coinNumValue", "cashFee"], requireAll = false)
fun bindRealCoinNum(
    view: TextView,
    coinNumValue: String?,
    cashFee: String?,
) {
    if (isCorrectNumber(coinNumValue)) {
        view.text =
            BigDecimal(coinNumValue).subtract(BigDecimal(cashFee)).toPlainString()
    } else {
        view.text = ""
    }
}

@BindingAdapter(value = ["cashAmount", "cashUrl", "smsCode"], requireAll = false)
fun setBtnEnable(
    view: Button,
    cashAmount: String?,
    cashUrl: String?,
    smsCode: String?,
) {
    view.isEnabled =
        isCorrectNumber(cashAmount) && !TextUtils.isEmpty(cashUrl) && !TextUtils.isEmpty(smsCode)
}